// 全局自定义指令

// 引入监听是否进入视口工具
import { useIntersectionObserver } from '@vueuse/core'

export const defineDirective = {
  install (app) {
    app.directive('imgLazy', {
      mounted (el, binding) {
        // el是指定绑定的dom元素,binding指令绑定值
        const { stop } = useIntersectionObserver(el, ([{ isIntersecting }], observerElement) => {
          if (isIntersecting) {
            el.src = binding.value
            stop()
          }
        })
      }
    })
  }
}
